﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MedReg
{
    public partial class MedicalCondition : IEquatable<MedicalCondition>
    {
        public void ImportList(List<Classes.MedicalCondition> mcList)
        {
            var mdb = new MedregDBDataContext();
            var ListMC = new List<MedicalCondition>();
            foreach (var mc in mcList)
            {
                MedicalCondition mc1 = new MedicalCondition() { ID = mc.ID, Name = mc.Name };
                MedicalCondition query;

                if (mdb.MedicalCondition.LongCount() == 0)
                {
                    mdb.MedicalCondition.InsertOnSubmit(mc1);
                }
                else
                {
                    try
                    {
                        query = mdb.MedicalCondition.Single(l => l.ID == mc1.ID);
                        query.Name = mc1.Name;

                    }
                    catch (ArgumentNullException e)
                    {
                    }
                    catch (InvalidOperationException e)
                    {

                        if (!ListMC.Contains(mc1))
                        {
                            mdb.MedicalCondition.InsertOnSubmit(mc1);
                            ListMC.Add(mc1);
                        }
                    }
                }
            }
            mdb.SubmitChanges();
        }
        public bool Equals(MedicalCondition other)
        {
            var i = this.ID.Equals(other.ID);
            var j = this.Name.Equals(other.Name);
            if (i & j)
            {
                return true;
            }
            return false;
        }
    }
}
